<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>event-auto-confirm-add</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	<script src="<%=request.getContextPath()%>/js/calendar/zh_CN_WdatePicker.js"></script>
	<script src="${pageContext.request.contextPath}/js/crontab/Simple_util.js"></script>
	<script src="<%=request.getContextPath()%>/js/crontab/Crontab.js"></script>
	<script src="<%=request.getContextPath()%>/js/crontab/Crontab_data_zh_CN.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit_data_zh_CN.js"></script>
	<style type="text/css">
		.tdValue{
			border: 1px solid #D6D3D6;
			line-height: 26px;
			height: 32px;
			padding-left: 5px;
			overflow: hidden;
		}
	</style>
	<script type="text/javascript">
	function add(){
		if(tunit.results() == '0'){
			getTopWin(window).getMessageBox().alert("间隔时间不能为空","提示");
			return false;
		}
		  //提交
		 $.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/event/event-auto-confirm!save.action?duration="+tunit.results(), //请求的action
			   data: $("#myform").serialize(), //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				   if(data == true){
					   var pWin = getTopWin(window).currentWin["add-event-auto-confirm"];
					   pWin.datagrid();
					   getTopWin(window).closejBox("add-event-auto-confirm");
				   }
				   
			   }
		});
	  }
		function closewin(){
		  	getTopWin(window).closejBox("add-event-auto-confirm");
	  	}
		$(function(){
			  $.formValidator.initConfig({formid:"myform"
		          ,onerror:function(msg){}
		          ,onsuccess:function(){
		        	  		add();
		          			return false;
		          }
		          });
			  $("#eventTypeId").formValidator({onshow:"不能为空",onfocus:"同一资源下不能重复",oncorrect:"输入正确",defaultvalue:"-1"}).inputValidator({min:1,onerror:"不能为空"})
			  .ajaxValidator({
					type : "post",
					async : false,
					url:'${pageContext.request.contextPath}/event/event-auto-confirm!checkEventTypeId.action',
					data: "eventTypeId="+$("#eventTypeId").val()+"&resId="+'${resId}',
					datatype : "json",
					success : function(data){
						if(data== true)
						{
							return true;
						}else
						{
							return false;
						}
		   			},
				buttons: $("#button"),
				error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
				onerror : "已经存在",
				onwait : "正在校验"
				});
		  });
	</script>
  </head>
  
  <body class="padding-8">
    <form action="" id="myform" name="myform" method="post">
    		<table class="table_eidt">
    			<tr>
	    			<td class="td_left" style="width:100px">资源名称</td>
	    			<td class="td_right">${resName}</td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>事件类别</td>
	    			<td class="td_right"><select name="eventTypeId" id="eventTypeId" style="width: 200px">
			          	<option value="-1">--请选择事件类别--</option>
			          	<c:forEach items="${listEventType}" var="e">
			          		<option value=${e.id}>${e.name}</option>
						</c:forEach>
			        </select>
			        <span id="eventTypeIdTip" style="width:120px"></span>
			        </td>
    			</tr>
    			<tr>
	    			<td class="td_left">间隔时间</td>
	    			<td class="tdValue">
	    			<div id="divDuration"></div>
	    				<script type="text/javascript">
	    				 	tunit = new SimpleTimeUnit("divDuration","ddHHmm");
	    				 	tunit.show();
				        </script>
	    			</td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:9px;">
	    		<button type="submit" id="button" name="button" class="btn-4">保存</button>
	    		<button type="reset" class="btn-4">重置</button>
	    		<button type="button" onclick="closewin();" class="btn-4">取消</button>
    		</div>
    		<input type="hidden" name="resId" id="resId" value=${resId}>
    	</form>
  </body>
</html>
